package org.video.mine.adapter;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;

import org.video.mine.BR;
import org.video.mine.R;
import org.video.mine.databinding.HomeTitleBinding;
import org.video.mine.entity.HomeTitleEntity;

import java.util.List;

public class HomeTitleAdapter extends RecyclerView.Adapter<HomeTitleAdapter.ViewHolder> {

    List<HomeTitleEntity> titleEntities;
    Context context;

    public HomeTitleAdapter(List<HomeTitleEntity> titleEntities, Context context) {
        this.titleEntities = titleEntities;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        HomeTitleBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),R.layout.home_title,parent,false);
        return new ViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        HomeTitleEntity titleEntity = titleEntities.get(position);
        Log.d("title===",titleEntity.getTitle());
        holder.getTitleBinding().setTitleModel(titleEntity);
    }

    @Override
    public int getItemCount() {
        return titleEntities.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        HomeTitleBinding titleBinding = null;

        public ViewHolder(HomeTitleBinding titleBinding) {
            super(titleBinding.getRoot());
            this.titleBinding = titleBinding;
        }

        public HomeTitleBinding getTitleBinding(){
            return titleBinding;
        }
    }
}
